import { Map } from 'immutable'

const reducer = (state = Map({
  isLogin: localStorage.getItem('isLogin') === 'true' || false,
  adminname: localStorage.getItem('adminname') || '',
  role: localStorage.getItem('role') * 1,
  token: localStorage.getItem('token') || ''
}), action) => {
  const { type, payload } = action
  switch (type) {
    case "CHANGE_LOGIN_STATE":
      return state.set('isLogin', payload)
    case "CHANGE_ADMIN_NAME":
      return state.set('adminname', payload)
    case "CHANGE_ROLE":
      return state.set('role', payload)
    case "CHANGE_TOKEN":
      return state.set('token', payload)
    default:
      return state
  }
}

export default reducer